import java.util.HashMap;
import java.util.Set;

/**
 * Holder object for multiple relations. This is primarily used to cut down on
 * building relation objects all over the place, and having to keep track of a
 * lot of relation objects floating around in UI logic.
 * 
 * @author Sean Clapp
 * 
 */
public class RelationHolder {

	private HashMap<String, Relation> relationHolder;
	private String name;
	private Set key;

	/**
	 * Constructor for this class.
	 * 
	 * @param name
	 *            - the name designated to this RelationHolder object. ex: BCNF
	 *            for a relationHolder object holding relations that are in BCNF
	 *            form
	 */
	public RelationHolder(String name) {
		super();
		this.name = name;
		relationHolder = new HashMap<String, Relation>();
	}

	/**
	 * Getter for the name of this relationHolder object.
	 * 
	 * @return the name of this relationHolder object.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Setter for the name of this relationHolder object
	 * 
	 * @param name
	 *            - String value that will be the name of this relationHolder
	 *            object
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Getter for the relationHolder HashMap.
	 * 
	 * @return an instances of the hashMap of the relationHolder
	 */
	public HashMap<String, Relation> getRelationHolder() {
		return relationHolder;
	}

	/**
	 * Getter method for returning a Relation by it's relationName
	 * 
	 * @param relationName
	 *            - The name passed to this method to identify the relation in
	 *            the RelationHolder object
	 * @return a Relation object based on it's RelationName
	 */
	public Relation getRelation(String relationName) {
		return relationHolder.get(relationName);
	}

	/**
	 * Prints all of the relations found in this RelationHolder object.
	 */
	public void printRelations() {
		System.out.println("Printing relations from: " + this.name);
		System.out.println();
		for (Relation r : relationHolder.values()) {
			if (!r.getRelation().isEmpty()) {
				System.out.print(r.getRelationName() + ": (");
				System.out.print("U= {" + r.getSetOfAllAttribs().toString()
						+ "}, D= {");
				r.print();
				System.out.println("} )");

			}
		}
	}
}
